import Vue from "vue";
import VueRouter from "vue-router";
import HomeView from "../views/HomeView.vue";

Vue.use(VueRouter);
// 重写push
let originPush = VueRouter.prototype.push;
VueRouter.prototype.push = function (location, resolve, reject) {
  if (resolve && reject) {
    originPush.call(this, location, resolve, reject);
  } else {
    originPush.call(
      this,
      location,
      () => {},
      () => {}
    );
  }
};
// 重写replace
let originReplace = VueRouter.prototype.replace;
VueRouter.prototype.relace = function (location, resolve, reject) {
  if (resolve && reject) {
    originReplace.call(this, location, resolve, reject);
  } else {
    originReplace.call(
      this,
      location,
      () => {},
      () => {}
    );
  }
};
const routes = [
  {
    // 首页
    path: "/",
    name: "home",
    component: HomeView,
    meta: {
      title: "MAC魅可",
    },
  },
  {
    // 商品，如果未指明子路由则跳回首页
    path: "/product",
    redirect: "/",
    component: () => import("../views/product/Product.vue"),
    children: [
      {
        // 眼妆
        path: "eye-makeup",
        name: "/product/eye-makeup",
        component: () => import("../views/product/eye/EyeMakeup.vue"),
        meta: {
          nav: ["彩妆", "眼部"], //动态生成导航
        },
      },
      // 唇膏路由
      {
        path: "lipsticks",
        name: "/product/lipsticks",
        component: () => import("../views/product/lipsticks/Lipsticks.vue"),
        meta: {
          nav: ["唇部", "唇膏"], //动态生成导航
        },
      },
      // 底妆路由
      {
        path: "foundation-all",
        name: "/product/foundation-all",
        component: () =>
          import("@/views/product/foundationAll/foundationAll.vue"),
        meta: {
          nav: ["彩妆", "面部"], //动态生成导航
        },
      },
      // 刷具路由
      {
        path: "brushes-all",
        name: "/product/brushes-all",
        component: () => import("@/views/product/brushes/brushesAll.vue"),
        meta: {
          nav: ["刷具", "全部刷具"], //动态生成导航
        },
      },
      // 护肤路由
      {
        path: "skin",
        name: "/product/skin",
        component: () => import("@/views/product/skin/Skin.vue"),
        meta: {
          nav: ["妆前护肤", "保湿护肤"], //动态生成导航
        },
      },

      {
        // 商品列表页，参数值：分类
        path: "list/:cid",
        name: "product-list",
        component: () => import("../views/product/ProductList.vue"),
        meta: {
          title: "MAC  商品",
        },
      },

      {
        // 商品详情，参数值：商品id
        path: "details/:pid",
        name: "product-details",
        component: () => import("../views/product/ProductDetails.vue"),
        meta: {
          title: "MAC  详情",
        },
      },
      {
        path: "floose-powder",
        name: "floose-powder",
        component: () =>
          import("@/views/product/foundationAll/F-loosePowder.vue"),
        meta: {
          nav: ["面部", "蜜粉散粉"], //动态生成导航
        },
      },
    ],
  },
  {
    // 搜索列表页
    path: "/search/:name",
    name: "search",
    component: () => import("../views/search/SearchList.vue"),
    meta: {
      title: "MAC  搜索",
    },
  },
  {
    path: "/about",
    name: "about",
    component: () => import("../views/AboutView.vue"),
  },
  {
    // 登录页
    path: "/mylogin",
    name: "mylogin",
    component: () => import("../views/account/MyLogin.vue"),
    meta: {
      title: "MAC  登录",
    },
  },
  {
    // 注册页
    path: "/register",
    name: "register",
    component: () => import("../views/account/Register.vue"),
    meta: {
      title: "MAC  注册",
    },
  },
  {
    // 账号页
    path: "/account",
    name: "myaccount",
    component: () => import("../views/account/MyAccount.vue"),
    children: [
      {
        // 个人信息
        path: "personal-data",
        name: "account/personal-data",
        component: () => import("../views/account/PersonalData.vue"),
        meta: {
          title: "MAC  个人信息",
        },
      },
      {
        // 订单
        path: "order",
        name: "order",
        component: () => import("../views/order/Order.vue"),
        meta: {
          title: "MAC  我的订单",
        },
      },
      {
        // 收货地址
        path: "logistics",
        name: "logistics",
        component: () => import("../views/account/ShipToList.vue"),
        meta: {
          title: "MAC  订单物流",
        },
      },
      {
        // 新增收货地址
        path: "logistics-update",
        name: "logistics-update",
        component: () => import("../views/account/ShipToAddress.vue"),
        meta: {
          title: "MAC  订单物流",
        },
      },
      {
        // 购物车
        path: "shopping",
        name: "shopping",
        component: () => import("../views/shopping/ShoppingList.vue"),
        meta: {
          title: "MAC  购物车",
        },
      },
    ],
  },
  {
    // 社区页
    path: "/community",
    name: "community",
    component: () => import("../views/community/Communtiy.vue"),
    meta: {
      title: "MAC  社区",
    },
  },
  {
    //门店页
    path: "/store/offline-stores",
    name: "store/offline-stores",
    component: () => import("../views/store/Offline-Stores.vue"),
    meta: {
      title: "MAC线下门店",
    },
  },
  {
    // 购买页
    path: "/buy",
    name: "buy",
    component: () => import("../views/order/Buy.vue"),
    meta: {
      title: "MAC 购买",
    },
  },
  {
    //商品散粉子页面
    path: "/product/makeup/loose-prwder",
    name: "product/makeup/loose-prwder",
    component: () => import("../views/product/makeup/Loose-PrwderView.vue"),
    meta: {
      nav: ["面部", "蜜粉散粉", "魅可定制无瑕轻盈散粉"], // 动态生成导航
    },
  },
];

const router = new VueRouter({
  mode: "history",
  routes,
});

export default router;
